package com.zjq.designpatterns.struct.appearance.code;/*
 * 版权信息: 北京千⾥马网信科技有限公司</br>
 * Copyright ©2008-2018. All rights reserved. 京ICP备16007318号
 */

/**
 * 应用层对接的时候要关注所有的服务，而且要按照顺序，其实用户只是关心积分兑换的功能，所以我们在这里提供一个外观类，
 * 对方不需要知道这么多子系统，迪米特法则，不该知道不知道
 * 所以这里提供这个类
 *
 * @author jessie
 * @version 1.0
 * @date 2021/1/22
 */
public class GiftExchangeService {
    //通过set注入
    private QualifyService qualifyService;
    private PointPaymentService pointPaymentService;
    private ShippingService shippingService;

    public QualifyService getQualifyService() {
        return qualifyService;
    }

    public void setQualifyService(QualifyService qualifyService) {
        this.qualifyService = qualifyService;
    }

    public PointPaymentService getPointPaymentService() {
        return pointPaymentService;
    }

    public void setPointPaymentService(PointPaymentService pointPaymentService) {
        this.pointPaymentService = pointPaymentService;
    }

    public ShippingService getShippingService() {
        return shippingService;
    }

    public void setShippingService(ShippingService shippingService) {
        this.shippingService = shippingService;
    }

    public void gitExchange(PointGift pointGift){
        if(qualifyService.isAvailable(pointGift)){
            //资格校验通过
            if(pointPaymentService.pay(pointGift)){
                //积分支付成功
                String shippingOrderNo = shippingService.shipGift(pointGift);
                System.out.println("物流系统下单成功,订单号是"+shippingOrderNo);
            }
        }
    }
}
